package org.example;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class IO_Demo21 {
    public static void main(String[] args) {
        //压缩流 压缩单个文件

        //要压缩的文件
        File src=new File("D:\\文件名");
        //压缩包的位置
        File dest=new File("D:\\");
    }
    public static void tozip(File src,File dest) throws IOException {
        ZipOutputStream zop=new ZipOutputStream(new FileOutputStream(new File(dest,"压缩包名.zip")));
        ZipEntry entry=new ZipEntry("D:\\文件名");//名字和原来一样
        zop.putNextEntry(entry);//把文件添加到压缩包 都是还没有数据
        //创建基本流读取数据
        FileInputStream fis=new FileInputStream(src);
        int len;
        while((len=fis.read())!=-1){
            zop.write(len);//
        }
        zop.closeEntry();
        zop.close();
    }
}
